package com.mock.action.governmentofficeregion;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import com.mock.dao.GovernmentOfficeRegionDao;
import com.mock.dao.impl.GovernmentOfficeRegionDaoImpl;
import com.mock.model.GovernmentOfficeRegion;
import com.opensymphony.xwork2.ActionSupport;

public class GovernmentOfficeRegionAction extends ActionSupport{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	

	private List<GovernmentOfficeRegion> listGOR;
	private GovernmentOfficeRegion bean ;

	private List<GovernmentOfficeRegion> listGORLookup;

	/*  Add or edit GOR  */
	private long idE ;
	private String nameE="";
	private String descriptionE;
	private String countryE;
	private boolean activeE;
	private long idGOR = -1L;
	

	/**
	 * Getter + setter 
	 */
	
	public long getIdE() {
		return idE;
	}
	public void setIdE(long idE) {
		this.idE = idE;
	}
	public String getNameE() {
		return nameE;
	}
	public void setNameE(String nameE) {
		this.nameE = nameE;
	}
	public String getDescriptionE() {
		return descriptionE;
	}
	public void setDescriptionE(String descriptionE) {
		this.descriptionE = descriptionE;
	}
	public String getCountryE() {
		return countryE;
	}
	public void setCountryE(String countryE) {
		this.countryE = countryE;
	}
	
	public boolean isActiveE() {
		return activeE;
	}
	public void setActiveE(boolean activeE) {
		this.activeE = activeE;
	}
	
	public List<GovernmentOfficeRegion> getListGOR() {
		return listGOR;
	}
	public void setListGOR(List<GovernmentOfficeRegion> listGOR) {
		this.listGOR = listGOR;
	}

	public long getIdGOR() {
		return idGOR;
	}

	public void setIdGOR(long idGOR) {
		this.idGOR = idGOR;
	}
	public GovernmentOfficeRegion getBean() {
		if (idGOR != -1L) bean = new GovernmentOfficeRegionDaoImpl().getById(GovernmentOfficeRegion.class, idGOR);
		return bean;
	}

	public void setBean(GovernmentOfficeRegion bean) {
		this.bean = bean;
	}
	
	
	/**
	 * 
	 * @return
	 */
	
	
	public List<GovernmentOfficeRegion> getListGORLookup() {
		return listGORLookup;
	}
	public void setListGORLookup(List<GovernmentOfficeRegion> listGORLookup) {
		this.listGORLookup = listGORLookup;
	}
	@Override
	public String execute() throws Exception {
		// TODO Auto-generated method stub
		GovernmentOfficeRegionDao dao = new GovernmentOfficeRegionDaoImpl();
		/*dao.add(new GovernmentOfficeRegion("LGOR 13","Qes1","VN",false));
		dao.add(new GovernmentOfficeRegion("HGOR 14","ADes2","VN",false));
		dao.add(new GovernmentOfficeRegion("AGOR 15","LDes3","Japan",false));
		dao.add(new GovernmentOfficeRegion("UGOR 13","Qes1","VN",true));
		dao.add(new GovernmentOfficeRegion("CGOR 14","CDes2","VN",true));
		dao.add(new GovernmentOfficeRegion("AGOR 15","LDes3","Japan",true));
		dao.add(new GovernmentOfficeRegion("CGOR 16","Jes4","Korea",true));
		dao.add(new GovernmentOfficeRegion("CGOR 16","Jes4","Korea",true));*/
		listGOR = dao.getAll(GovernmentOfficeRegion.class);
		/*for (GovernmentOfficeRegion gor : listGOR){
			System.out.println(gor);
		}*/
		return SUCCESS;
	}
	
	
	public String view() {
		return SUCCESS;
	}
	
	public String update(){
		GovernmentOfficeRegionDao dao = new GovernmentOfficeRegionDaoImpl();
		GovernmentOfficeRegion bean = dao.getById(GovernmentOfficeRegion.class, idE);
		bean.setGovernmentOfficeRegionName(nameE);
		bean.setDescription(descriptionE);
		bean.setCountry(countryE);
		bean.setActive(activeE);
		dao.update(bean);
		return SUCCESS;
	}
	
	
	
	
	public String create(){
		GovernmentOfficeRegionDao dao = new GovernmentOfficeRegionDaoImpl();
		listGORLookup = dao.getAll(GovernmentOfficeRegion.class);
		if ( "".equals(nameE) ) return ERROR;
		GovernmentOfficeRegion gor = new GovernmentOfficeRegion();
		gor.setGovernmentOfficeRegionName(nameE);
		gor.setDescription(descriptionE);
		gor.setCountry(countryE);
		gor.setActive(activeE);
		
		System.out.println("name = "+ nameE);
		System.out.println("country = "+ countryE);
		System.out.println("Active = "+ activeE);
		dao.add(gor);
		return SUCCESS;
	}
	

	public String changeActive(){
		System.out.println("id = "+ idGOR);
		GovernmentOfficeRegionDao dao = new GovernmentOfficeRegionDaoImpl();
		try {
			GovernmentOfficeRegion bean = dao.getById(GovernmentOfficeRegion.class, idGOR);
			bean.setActive(true);
			dao.update(bean);
		} catch(Exception ex){
			System.out.println("Error : "+ ex.getMessage());
		}
		return SUCCESS;
	}
	
	
}
